#include "StdAfx.h"
#include "CallBack.h"

#include <atlconv.h>
#include <afxext.h> 

using namespace net;

extern void appendText(const wchar_t* text);

CallBack::CallBack(void): type(DISCOVER_OBJECT_INSTANCE)
{
}

CallBack::CallBack(char* raw)
{
	this->raw = raw;
	if(raw[0] == 'r')
		this->type = REFLECT_ATTRIBUTE_VALUES;
	else
		this->type = DISCOVER_OBJECT_INSTANCE;
}

CallBack::~CallBack(void)
{
}

void CallBack::visit(PDAfederateAmbassador* famb)
{
	ATL::CA2W pszW(this->raw);
	LPWSTR pszTemp;

	pszTemp = (LPWSTR) VirtualAlloc((LPVOID) NULL, 
		(DWORD) (wcslen(pszW) + 1), MEM_COMMIT, 
		PAGE_READWRITE);

	wcscpy(pszTemp, pszW);
	wcscat(pszTemp, L"\n\0");

	switch(this->type)
	{
	case DISCOVER_OBJECT_INSTANCE:
		famb->discoverObjectInstance(pszTemp);
		break;
	case REFLECT_ATTRIBUTE_VALUES:
		famb->reflectAttributeValues(pszTemp);
		break;
	default:
		break;
	}
}
